package org.example.journal_items.ServerImpl;

import org.example.journal_items.Entity.User;
import org.example.journal_items.Server.UserLoginServer;
import org.example.journal_items.UserDao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserLoginServerImpl implements UserLoginServer {
    @Autowired
    private UserDao userDao;

    @Override
    public Boolean validateCredentials(String username, String rawPassword) {
        // 先查询用户是否存在
        User user = userDao.findByUsername(username);

        if (user == null) {
            return false;
        }

        // 如果密码是明文存储(不推荐)
        return user.getPassword().equals(rawPassword);

        // 如果密码是加密存储(推荐)
        // return passwordEncoder.matches(rawPassword, user.getPassword());
    }
}